]> git.neil.brown.name Git - wiggle.git/commitdiff
Allow a word to have an unmatched prefix and suffix.
authorNeilBrown <neilb@suse.de>
Fri, 1 Mar 2013 08:05:27 +0000 (19:05 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 1 Mar 2013 08:05:27 +0000 (19:05 +1100)
i.e. The part of a word that is tested for matching is
shorted than the whole word that is printed.  There can
be a prefix and a suffix.  In a future patch, an option
will be availble to include most spaces as prefix or suffix
of nearby non-space.

Signed-off-by: NeilBrown <neilb@suse.de>
split.c
vpatch.c
wiggle.c
wiggle.h

diff --git a/split.c b/split.c
index 9455768f08fa7b98a868f1c471533e3368ce681a..a2880acb8a7bf6a16adc45144d30980154cda4b3 100644 (file)
--- a/split.c
+++ b/split.c
@@ -88,6 +88,8 @@ static int split_internal(char *start, char *end, int type,
                if (list) {
                        list->start = start;
                        list->len = cp-start;
+                       list->plen = list->len;
+                       list->prefix = 0;
                        if (*start)
                                list->hash = hash(start, list->len, 0);
                        else
index 29094c6304663b3877213f2e5941f1746ea10294..8d41a78793f880c1f9db94574cee1c0b783f412b 100644 (file)
--- a/vpatch.c
+++ b/vpatch.c
@@ -963,14 +963,14 @@ static void draw_mside(int mode, int row, int offset, int start, int cols,
                        continue;
                if (e.start[0] == 0)
                        continue;
-               c = (unsigned char *)e.start;
+               c = (unsigned char *)e.start - e.prefix;
                highlight_space = 0;
                attr = visible(mode, m, &pos);
                if ((attr == a_unmatched || attr == a_extra) &&
                    changed &&
                    (*c == ' ' || *c == '\t'))
                        highlight_space = 1;
-               for (l = 0; l < e.len; l++) {
+               for (l = 0; l < e.plen + e.prefix; l++) {
                        int scol = col;
                        (void)attrset(attr);
                        if (*c >= ' ' && *c != 0x7f) {
index 3648249f005c4b6cac45b95e37a3497def4d2252..f084957202d85d025ec989ae9e438d296fb73101 100644 (file)
--- a/wiggle.c
+++ b/wiggle.c
@@ -114,7 +114,8 @@ void *xmalloc(int size)
 void printword(FILE *f, struct elmnt e)
 {
        if (e.start[0])
-               fprintf(f, "%.*s", e.len, e.start);
+               fprintf(f, "%.*s", e.plen + e.prefix,
+                       e.start - e.prefix);
        else {
                int a, b, c;
                sscanf(e.start+1, "%d %d %d", &a, &b, &c);
index cac2725c4db46b3e88d24800ea11740d4d2b2bb2..8043da45871134a5dd46dc901208dcf12c7ffef6 100644 (file)
--- a/wiggle.h
+++ b/wiggle.h
@@ -51,7 +51,7 @@ struct stream {
 struct elmnt {
        char *start;
        int hash;
-       int len;
+       short len, plen, prefix;
 };
 
 static  inline int match(struct elmnt *a, struct elmnt *b)
@@ -71,7 +71,7 @@ static inline int ends_line(struct elmnt e)
 {
        if (e.len == 20 && e.start[0] == 0)
                return 1;
-       return e.len &&  e.start[e.len-1] == '\n';
+       return e.len &&  e.start[e.plen-1] == '\n';
 }
 
 struct csl {